import type algoliasearchFC from 'algoliasearch/lite';
import getResultByPagefind from './utils/getResultByPagefind';

/**
 * 构造一个 algoliasearch 实例
 * 
 * 打包以及服务端渲染情况下总是返回空的搜索结果
 */
function useSearchClient() {
  return {
    async search(requests: Parameters<ReturnType<typeof algoliasearchFC>["search"]>["0"]) {
      const query = requests[0].params?.query || ""

      return await getResultByPagefind(query)
    },
  } as unknown as ReturnType<typeof algoliasearchFC>;
}

export default useSearchClient;
